package com.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpSession;

/**
 * 通过特定规则, 达到不同会话使用同一session的目的
 * @author Administrator
 *
 */
public class UniqueSessionFilter implements Filter{

	public void destroy() {
		
	}

	public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
		final HttpServletRequest request = (HttpServletRequest) servletRequest;
		chain.doFilter(new HttpServletRequestWrapper(request){  
		    public HttpSession getSession(boolean create) {  
		    	ServletContext servletContext = request.getSession().getServletContext();
		    	/**
		    	 * TODO 获取session
		    	 */
		    	HttpSession session = null;
		        return session;  
		    }  
		}, servletResponse);
	}

	public void init(FilterConfig config) throws ServletException {
		
	}

}
